package dotnetbusinesscomponenthasservice;

import java.util.Arrays;
import org.eclipse.viatra2.emf.incquery.runtime.api.IPatternMatch;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BasePatternMatch;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.Pattern;
import sysmodel.Component;

/**
 * Pattern-specific match representation of the DotNetBusinessComponentHasService pattern, 
 * to be used in conjunction with DotNetBusinessComponentHasServiceMatcher.
 * 
 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
 * Each instance is a (possibly partial) substitution of pattern parameters, 
 * usable to represent a match of the pattern in the result of a query, 
 * or to specify the bound (fixed) input parameters when issuing a query.
 * 
 * @see DotNetBusinessComponentHasServiceMatcher
 * @see DotNetBusinessComponentHasServiceProcessor
 * 
 */
public final class DotNetBusinessComponentHasServiceMatch extends BasePatternMatch implements IPatternMatch {
  private Component fComponent;
  
  private static String[] parameterNames = {"component"};
  
  public DotNetBusinessComponentHasServiceMatch(final Component pComponent) {
    this.fComponent = pComponent;
    
  }
  
  @Override
  public Object get(final String parameterName) {
    if ("component".equals(parameterName)) return this.fComponent;
    return null;
    
  }
  
  public Component getComponent() {
    return this.fComponent;
    
  }
  
  @Override
  public boolean set(final String parameterName, final Object newValue) {
    if ("component".equals(parameterName) && newValue instanceof sysmodel.Component) {
    	this.fComponent = (sysmodel.Component) newValue;
    	return true;
    }
    return false;
    
  }
  
  public void setComponent(final Component pComponent) {
    this.fComponent = pComponent;
    
  }
  
  @Override
  public String patternName() {
    return "DotNetBusinessComponentHasService";
    
  }
  
  @Override
  public String[] parameterNames() {
    return DotNetBusinessComponentHasServiceMatch.parameterNames;
    
  }
  
  @Override
  public Object[] toArray() {
    return new Object[]{fComponent};
    
  }
  
  @Override
  public String prettyPrint() {
    StringBuilder result = new StringBuilder();
    result.append("\"component\"=" + prettyPrintValue(fComponent)
    );return result.toString();
    
  }
  
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((fComponent == null) ? 0 : fComponent.hashCode()); 
    return result; 
    
  }
  
  @Override
  public boolean equals(final Object obj) {
    if (this == obj)
    	return true;
    if (obj == null)
    	return false;
    if (!(obj instanceof IPatternMatch))
    	return false;
    IPatternMatch otherSig  = (IPatternMatch) obj;
    if (!pattern().equals(otherSig.pattern()))
    	return false;
    if (!DotNetBusinessComponentHasServiceMatch.class.equals(obj.getClass()))
    	return Arrays.deepEquals(toArray(), otherSig.toArray());
    				DotNetBusinessComponentHasServiceMatch other = (DotNetBusinessComponentHasServiceMatch) obj;
    				if (fComponent == null) {if (other.fComponent != null) return false;}
    				else if (!fComponent.equals(other.fComponent)) return false;
    				return true;
    
  }
  
  @Override
  public Pattern pattern() {
    return DotNetBusinessComponentHasServiceMatcher.FACTORY.getPattern();
  }
}
